home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / 2DBUMP.ZIP / DAN.CC < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-11  |  1.3 KB  |  76 lines

  1. #include "grx.h"
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <conio.h>
  5. #include "mouse.h"
  6. #include <time.h>
  7. #include <iostream.h>
  8. #include <math.h>
  9.  
  10. void Bump();
  11. void Init();
  12.  
  13. byte *hmap;
  14. byte litemap[256*256];
  15. int frames=0;
  16. void main()
  17. {
  18.    RGBcolor*p=load_pal_from_file("palette.pcx");
  19.    hmap=load_pic_from_file("height.pcx");
  20.    gmode(0x13);
  21.    setpal(p);
  22.    Init();
  23.    clock_t start,finish;
  24.    start=clock();
  25.    while(!kbhit()) {Bump();};
  26.    finish=clock();
  27.    gmode(0x3);
  28.    cout << "FPS = "<<frames*CLK_TCK/(finish-start);
  29. };
  30.  
  31. void Init()
  32. {
  33.    float nX,nY,nZ;
  34.    for (int y=0;y<256;y++)
  35.    for (int x=0;x<256;x++)
  36.    {
  37.       nX=(x-128)/128.0;
  38.       nY=(y-128)/128.0;
  39.       nZ=1-sqrt(nX*nX+nY*nY);
  40.       if (nZ<0) nZ=0;
  41.       litemap[x+y*256]=(byte)(255<?(nZ*191+nZ*nZ*nZ*nZ*nZ*nZ*nZ*nZ*nZ*64));
  42.    };
  43.  
  44. };
  45.  
  46.  
  47.  
  48. void Bump()
  49. {
  50.    frames++;
  51.    int nx,ny;
  52.    int rx,ry;
  53.    int i=320*1;
  54.    mouse_info mi=get_m_info();
  55.    for (int y=1;y<198;y++)
  56.    for (int x=0;x<320;x++)
  57.    {
  58.       nx=hmap[i+1]-hmap[i-1];
  59.       ny=hmap[i+320]-hmap[i-320];
  60.  
  61.       rx=x - mi.x;
  62.       ry=y - mi.y;
  63.  
  64.       nx-=rx;
  65.       ny-=ry;
  66.  
  67.       nx+=128;
  68.       ny+=128;
  69.       if (nx>255 || nx<0) nx=255;
  70.       if (ny>255 || ny<0) ny=255;
  71.       dbuffer[i]=litemap[nx+ny*256];
  72.       i++;
  73.    };
  74.    update_screen();
  75. };
  76.